﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using TouchRC.Logic;
using System.IO;
using TouchRC.MetadataCaching;

namespace TouchRC.Classes
{
    public class ComputerListBoxItem
    {
        private MetadataCollection m_MetadataCollection = null;

        public ComputerListBoxItem()
        {
            // Id = ConfigSettings.GetNextFreeId();
            RemotePort = 40500;
            ListeningPort = 40400;
        }

        public int Id { get; internal set; }
        public string Name { get; set; }
        public string DnsAddress { get; set; }
        public int RemotePort { get; set; }
        public int ListeningPort { get; set; }
        public bool IsLive { get; set; }
        public DirectoryInfo MetadataCacheDir { get; set; }
        public MetadataCollection MetadataCollection
        {
            get
            {
                if (m_MetadataCollection == null)
                {
                    CachingHelper helper = new CachingHelper();
                    m_MetadataCollection = helper.ReadSummaries(MetadataCacheDir);
                }
                return m_MetadataCollection;
            }
        }
        
        public override bool Equals(object obj)
        {
            if (obj is ComputerListBoxItem)
            {
                return Id.Equals(((ComputerListBoxItem)obj).Id);
            }
            return false;
        }
    }
}
